<template>
  <div>
    <div v-if="model.id">
      <a-card :bordered="false">
        <div slot="extra" v-if="model.state !== 2">
          <a-button type="primary" @click="handleEditOrg">编辑</a-button>
          <a-button type="primary" @click="handleBuy" v-if="model.state === 2">续费</a-button>
          <a-button type="primary" @click="handleBuy" v-if="model.state === 3">订购</a-button>
        </div>
        <div slot="title">
          {{ model.name === '未注册' ? '暂无' : model.name }}
        </div>
        <div slot="extra">
          <span>状态：{{ filterDictTextByCache("organization_state", model.state) }}</span>
        </div>
        <a-row :gutter="[24,12]">
          <a-col v-for="item in model.selectModules" :span="8" :key="item.id">
            <a-card style="min-width: 260px;" hoverable>
              <template slot="actions" >
                <!-- <a-icon key="setting" type="setting" /> -->
                <a key="edit" type="edit">查看</a>
                <a-icon key="ellipsis" type="ellipsis" />
              </template>
              <a-card-meta :title="item.moduleName" :description="'有效期：' + item.expire" @click="handleRoute(item.url)">
              </a-card-meta>
            </a-card>

          </a-col>
        </a-row>

      </a-card>
      <a-card style="margin-top: 12px;" :bordered="false">
        <div slot="extra">
        </div>
        <div slot="title">
          企业碳排放信息
        </div>
        <a-table :columns="columns" :dataSource="data" :pagination="false" :loading="loading"
          :rowKey="record => record.id" :scroll="{ x: 800 }">
        </a-table>
      </a-card>

      <a-row :gutter="24" style="margin-top: 20px;">
        <a-col :span="8">
          <a-card title="产品碳排" :bordered="false">
            <p>card content</p>
          </a-card>
        </a-col>
        <a-col :span="8">
          <a-card title="产品碳排" :bordered="false">
            <p>card content</p>
          </a-card>
        </a-col>
        <a-col :span="8">
          <a-card title="产品碳排" :bordered="false">
            <p>card content</p>
          </a-card>
        </a-col>
      </a-row>
    </div>
    <div v-else>
      <a-card title="平台说明" :bordered='false' :body-style="{ height: 'calc(100vh - 180px)', overflow: 'auto' }">
        <div slot="extra">
          <a-button type="primary" @click="handleRegister">立刻注册</a-button>
        </div>
        <a-row :gutter="[24, 16]" justify="center" style="background-color: #d7d9e330;">
          <a-col span="8" :offset="8" style="height: 300px; ">
            <a-card><span>企业介绍页面</span></a-card></a-col>
          <a-col span="8" :offset="8" style="height: 300px;"> <a-card><span>包含模块</span></a-card></a-col>
          <a-col span="8" :offset="8" style="height: 300px;"> <a-card><span>功能</span></a-card></a-col>
        </a-row>

      </a-card>
    </div>

    <register-organize-modal ref="orgModal" @ok="handleOK" @close="handleClose" />
  </div>

</template>

<script>
import { getAction } from '@/api/manage'
import RegisterOrganizeModal from './RegisterOrganizeModal.vue'
import { filterDictTextByCache } from '@/components/dict/JDictSelectUtil';

export default {
  name: "Analysis",
  components: {
    RegisterOrganizeModal
  },
  data() {
    return {
      model: {},
      loading: true,
      columns: [
        { title: '产品名称', dataIndex: 'productName' },
        { title: '产品类型', dataIndex: 'productType' },
        { title: '产品数量', dataIndex: 'productNum' },
        { title: '产品单价', dataIndex: 'productPrice' },
        { title: '产品单位', dataIndex: 'productUnit' },
      ],
      data: [
        { productName: '产品名称1', productType: '产品类型1', productUnit: '产品单位1', productNum: '产品数量1', productPrice: '产品单价1' },
        { productName: '产品名称2', productType: '产品类型2', productUnit: '产品单位2', productNum: '产品数量2', productPrice: '产品单价2' },
      ],
      url: {
        org: "/platform/cyPlatformOrganizationInfo/current"
      }
    }
  },
  created() {
    this.getOrgInfo()
  },
  methods: {
    filterDictTextByCache,
    handleRoute(url){
      // this.$router.push(url + '/index');
    },
    getOrgInfo() {
      this.loading = true
      getAction(this.url.org, {}).then((res) => {
        if (res.result) {
          this.model = res.result
        } else {
          this.$message.warning("组织未注册，请尽快注册")
        }
      }).finally(() => {
        this.loading = false
      })
    },
    handleRegister() {
      this.$refs.orgModal.register()
    },
    handleEditOrg() {
      this.$refs.orgModal.edit(this.model)
    },
    handleOK() {
      this.getOrgInfo()
    },
    handleClose() {


    }
  }
}
</script>